package cn.sintang.test.annotation.fruit;

import java.lang.reflect.Field;

/**
 * 水果注解工具类
 * @author txy
 * @date 2017/12/7 16:26
 */
public class FruitReflectUtil {
    public static void getFruitInfo(Class<?> clazz){
        StringBuilder fruitInfo = new StringBuilder();
        Field[] fields = clazz.getDeclaredFields();
        for(Field field : fields){
            if(field.isAnnotationPresent(FruitName.class)){
                FruitName fruitName = field.getAnnotation(FruitName.class);
                fruitInfo.append(" 水果名称:"+fruitName.value());
            }else if(field.isAnnotationPresent(FruitColor.class)){
                FruitColor fruitColor = field.getAnnotation(FruitColor.class);
                fruitInfo.append(" 水果颜色:"+fruitColor.fruitColor().getName()+"("+fruitColor.fruitColor()+")");
            }else if(field.isAnnotationPresent(FruitProvider.class)){
                FruitProvider fruitProvider = field.getAnnotation(FruitProvider.class);
                fruitInfo.append(" 水果供应："+fruitProvider.name()).append(","+fruitProvider.address());
            }
        }
        System.out.println(fruitInfo.toString());
    }

    public static void main(String[] args) {
        getFruitInfo(Apple.class);
    }
}
